/*
 * ROMEFeedEntryImpl.java
 *
 * Created on August 13, 2007, 1:23 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package com.afaker.rss.feed;

import com.sun.syndication.feed.module.DCModuleImpl;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndEntry;
import java.util.Date;
import java.util.List;

/**
 *
 * @author bruce
 */
public class ROMEFeedEntryImpl implements FeedEntry {

    private SyndEntry entry;
    private String feedName;

    /** Creates a new instance of ROMEFeedEntryImpl */
    public ROMEFeedEntryImpl(SyndEntry entry, String feedName) {
        this.entry = entry;
        this.feedName = feedName;
    }

    public String getTitle() {
        return entry.getTitle();
    }

    public String getAuthor() {
        return entry.getAuthor();
    }

    public List getCategories() {
        return entry.getCategories();
    }

    public List getContents() {
        return entry.getContents();
    }

    public String getDescription() {
        SyndContent description = entry.getDescription();
        if (description != null) {
            return description.getValue();
        }else{
            return "";
        }
    }

    public String getLink() {
        return entry.getLink();
    }

    public List getModules() {
        return entry.getModules();
    }

    public String getURI() {
        return entry.getUri();
    }

    public Date getPublishedDate() {
        return entry.getPublishedDate();
    }

    public Date getUpdateDate() {
        return entry.getUpdatedDate();
    }

    public String toString() {
        StringBuffer string = new StringBuffer();
        String content2 = null;
        if (getContents().size() > 0) {
            content2 = ((SyndContent) getContents().get(0)).getValue();
            if (content2 == null) {
                content2 = "";
            }
            string.append(content2);
        } else {
            String content = getDescription();
            //rss2.0
            if (content != null) {
                string.append(content);
            } //rss1.0
            else {

                DCModuleImpl module = (DCModuleImpl) getModules().listIterator().next();
                string.append(module.getDescription());
            }
        }
        return string.toString();
    }

    public String toHTML() {

        StringBuffer html = new StringBuffer();
        String content2 = null;
        String date = "";
        if (getPublishedDate() != null) {
            date = getPublishedDate().toString();
        }
        String insertHTML = "<h1>" + entry.getTitle() + "</h1>" +
                "<a href=\"" + getLink() + "\">" + getLink() + "</a>" +
                //+"<img src=\""+"\">" +
                "<div class=\"post\">" +//<div class=\"header\">" +
                //"<h3>TerraFirma<sup>1.0</sup> by NodeThirtyThree</h3>" +
                "<div class=\"date\">" + date + "</div>" + "</div>" +
                "<div class=\"content\">" +
                "<p>";
        //"<img src=\""+"\" alt=\"\" />" +
        String tail = "</p>" +
                "</div>" +
                "<div class=\"footer\">" +
                "<ul><li class=\"printerfriendly\">" +
                "<a href=\"#\">Printer Friendly</a>" +
                "</li></ul>" +
                "</div></div>";

        html.append(insertHTML);
        html.append(toString());
        html.append(tail);
        return html.toString();
    }

    public String getFeedName() {
        return feedName;
    }
}
